#include <QtNetwork>
#include <QDebug>
#include "netacman.h"

NetworkAccessManager::NetworkAccessManager(QNetworkAccessManager *manager, QObject *parent) :
    QNetworkAccessManager(parent)
{
    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    diskCache->setCacheDirectory("cacheDir");
    setCache(diskCache);
    setCookieJar(manager->cookieJar());
    setProxy(manager->proxy());
    setProxyFactory(manager->proxyFactory());

//    connect(this, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
}

QNetworkReply *NetworkAccessManager::createRequest(
    QNetworkAccessManager::Operation operation, const QNetworkRequest &request,
    QIODevice *device)
{
//    qDebug() << "request: " << request.header(QNetworkRequest::ContentTypeHeader).toString();
    return QNetworkAccessManager::createRequest(operation, request, device);
}

void NetworkAccessManager::replyFinished(QNetworkReply */*reply*/)
{
//    qDebug() << "reply: " << reply->operation();
//    QString header = reply->header(QNetworkRequest::ContentTypeHeader).toString();
//    qDebug() << "reply: " << header;

//    if (header.contains("text/html"))
//    {
//        qDebug() << reply->readAll();
//    }
}
